/****************************************************************************
**
** CreateCharacterGump.cpp
**
** Copyright (C) August 2014 Hotride
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
*****************************************************************************
*/
//---------------------------------------------------------------------------
#include "stdafx.h"
//---------------------------------------------------------------------------
TCreateCharacterGump::TCreateCharacterGump()
{
}
//---------------------------------------------------------------------------
TCreateCharacterGump::~TCreateCharacterGump()
{
}
//---------------------------------------------------------------------------
void TCreateCharacterGump::Init()
{
	UO->m_CharacterCreate.Clear();
}
//---------------------------------------------------------------------------
int TCreateCharacterGump::Render(bool mode)
{
	DWORD ticks = GetTickCount();

	if (g_LastRenderTime > ticks)
	{
		if (mode || !g_SelectGumpObjects) return 0;
	}

	if (mode)
	{
		WORD cell = 10;

		int CanSelectedButton = g_LastSelectedObject;

		int CanPressedButton = 0;
		if (g_LeftMouseDown && g_LastObjectLeftMouseDown == g_LastSelectedObject) CanPressedButton = g_LastObjectLeftMouseDown;
	
		g_LastRenderTime = ticks + g_FrameDelay;

		UO->m_GL.BeginDraw();

		UO->DrawGump(0x0588, 0, 0, 0, 640, 480); //Main Gump background
		UO->DrawGump(0x157C, 0, 0, 0); //Main Gump
		UO->DrawGump(0x15A0, 0, 0, 4); //Main Gump Notes
		
		WORD GumpID = 0x1589 + (int)(CanSelectedButton == 1); //X gump /lighted
		if (CanPressedButton == 1) GumpID = 0x158B; //X gump (pressed)
		UO->DrawGump(GumpID, 0, 555, 4);
		
		GumpID = 0x15A1 + (int)(CanSelectedButton == 2); //< gump /lighted
		if (CanPressedButton == 2) GumpID = 0x15A3; //< gump pressed
		UO->DrawGump(GumpID, 0, 586, 445); //< gump

		GumpID = 0x15A4 + (int)(CanSelectedButton == 3); //> gump /lighted
		if (CanPressedButton == 3) GumpID = 0x15A6; //> gump pressed
		UO->DrawGump(GumpID, 0, 610, 445); //> gump

		UO->DrawResizepicGump(0x0E10, 82, 125, 151, 310); //Create character field
		
		UO->DrawGump(0x0709, 0, 280, 53); //Character name gump

		UO->DrawGump(0x070A, 0, 240, 73); //Character name field (
		UO->DrawGump(0x070B, 0, 248, 73, 215, 0); //Character name field body
		UO->DrawGump(0x070C, 0, 463, 73); //Character name field )
		
		if (UO->m_CharacterCreate.GetName().length()) UO->m_Font->DrawA(5, UO->m_CharacterCreate.GetName().c_str(), 1, 257, 65);
		int TextLen = UO->m_Font->GetWidthA(5, UO->m_CharacterCreate.GetName().c_str(), UO->m_CharacterCreate.GetNamePos());
		UO->m_Font->DrawA(5, "_", 1, 257 + TextLen, 67);
		
		UO->DrawGump(0x0708, 0, 238, 98); //Cheate character podium
		
		UO->DrawResizepicGump(0x0E10, 475, 125, 151, 310); //Create character field
		
		WORD FColor = 0;
		if (!UO->m_CharacterCreate.GetSex())
		{
			UO->m_Font->DrawA(9, "Facial Hair Style", 0x0481, 100, 187);
			if (UO->m_CharacterCreate.GetSelectFace() != 2)
			{
				UO->DrawResizepicGump(0xBB8, 97, 199, 121, 24); //Facial Hair Style text field
				UO->m_Font->DrawA(9, UO->m_CharacterCreate.GetFacialHair(UO->m_CharacterCreate.GetFacialHairStyle()).Name.c_str(), 0x0386, 101, 205, 117.0f, TS_FIXED);
				UO->DrawGump(0x00FD, 0, 200, 201); //v gump
			}
			else
			{
				UO->DrawResizepicGump(0xBB8, 97, 199, 177, 142); //Facial Hair Style text field extended
				for (int i = 0; i < 8; i++)
				{
					FColor = 0x0386;
					if (CanSelectedButton == 20  + i) FColor = 0x0021;
					UO->m_Font->DrawA(9, UO->m_CharacterCreate.GetFacialHair(i).Name.c_str(), FColor, 101, 205 + (i * 14));
				}
			}
		}

		UO->m_Font->DrawA(9, "Hair Style", 0x0481, 100, 142);
		if (UO->m_CharacterCreate.GetSelectFace() != 1)
		{
			UO->DrawResizepicGump(0xBB8, 97, 154, 121, 24); //Hair Style text field
			UO->m_Font->DrawA(9, UO->m_CharacterCreate.GetHair(UO->m_CharacterCreate.GetHairStyle()).Name.c_str(), 0x0386, 101, 159);
			UO->DrawGump(0x00FD, 0, 200, 156); //v gump
		}
		else
		{
			UO->DrawResizepicGump(0xBB8, 97, 154, 130, 170); //Hair Style text field extended
			for (int i = 0; i < 10 + (int)UO->m_CharacterCreate.GetSex(); i++)
			{
				FColor = 0x0386;
				if (CanSelectedButton == 20  + i) FColor = 0x0021;
				UO->m_Font->DrawA(9, UO->m_CharacterCreate.GetHair(i).Name.c_str(), FColor, 101, 159 + (i * 14));
			}
		}
		
		if (UO->m_CharacterCreate.GetSelectColor() == 1)
		{
			glDisable(GL_TEXTURE_2D);
			for (int x = 0; x < 8; x ++)
			{
				for (int y = 0; y < 8; y++)
				{
					FColor = 0x3EA + (x * 8 + (x < 7 ? y : 0));
					if (FColor > 0x0422) FColor = 0x0422;
					DWORD clr = UO->m_ColorManager->GetPolygoneColor(cell, FColor);
					UO->m_GL.DrawPolygone(clr, 490 + (x * 15), 140 + (y * 35.0f), 15.0f, 35.0f);
					if (g_LastSelectedObject == 40 + (x * 8 + y)) UO->m_GL.DrawPolygone(0x007F7F7F, 490 + ((x * 15) + 6.5f), 140 + ((y * 35.0f) + 16.5f), 2.0f, 2.0f);
				}
			}
			glColor3f(1.0f, 1.0f, 1.0f);
			glEnable(GL_TEXTURE_2D);
		}
		else if (UO->m_CharacterCreate.GetSelectColor() == 0)
		{
			FColor = 0x0481;
			if (CanSelectedButton == 7) FColor = 0x0021;
			UO->m_Font->DrawA(9, "Skin Tone", FColor, 490, 140);

			glDisable(GL_TEXTURE_2D);

			FColor = UO->m_CharacterCreate.GetSkinTone();
			if (FColor < 0x03EA) FColor = 0x03EA;
			if (FColor > 0x0422) FColor = 0x0422;
			DWORD clr = UO->m_ColorManager->GetPolygoneColor(cell, FColor);
			UO->m_GL.DrawPolygone(clr, 490, 154, 120, 25);

			glColor3f(1.0f, 1.0f, 1.0f);
			glEnable(GL_TEXTURE_2D);
		}
		
		if (UO->m_CharacterCreate.GetSelectColor() == 2)
		{
		}
		else if (UO->m_CharacterCreate.GetSelectColor() == 0)
		{
			FColor = 0x0481;
			if (CanSelectedButton == 8) FColor = 0x0021;
			UO->m_Font->DrawA(9, "Shirt Color", FColor, 490, 185);

			glDisable(GL_TEXTURE_2D);

			FColor = UO->m_CharacterCreate.GetShirtColor();
			//if (FColor < 0x044E) FColor = 0x044E;
			//if (FColor > 0x04AD) FColor = 0x04AD;
			DWORD clr = UO->m_ColorManager->GetPolygoneColor(cell, FColor);
			UO->m_GL.DrawPolygone(clr, 490, 199, 120, 25);

			glColor3f(1.0f, 1.0f, 1.0f);
			glEnable(GL_TEXTURE_2D);
		}
		
		if (UO->m_CharacterCreate.GetSelectColor() == 3)
		{
		}
		else if (UO->m_CharacterCreate.GetSelectColor() == 0)
		{
			FColor = 0x0481;
			if (CanSelectedButton == 9) FColor = 0x0021;
			if (UO->m_CharacterCreate.GetSex()) UO->m_Font->DrawA(9, "Skirt Color", FColor, 490, 230);
			else UO->m_Font->DrawA(9, "Pants Color", FColor, 490, 230);

			glDisable(GL_TEXTURE_2D);

			FColor = UO->m_CharacterCreate.GetPantsColor();
			//if (FColor < 0x044E) FColor = 0x044E;
			//if (FColor > 0x04AD) FColor = 0x04AD;
			DWORD clr = UO->m_ColorManager->GetPolygoneColor(cell, FColor);
			UO->m_GL.DrawPolygone(clr, 490, 244, 120, 25);

			glColor3f(1.0f, 1.0f, 1.0f);
			glEnable(GL_TEXTURE_2D);
		}

		if (UO->m_CharacterCreate.GetSelectColor() == 4)
		{
			glDisable(GL_TEXTURE_2D);
			for (int x = 0; x < 6; x ++)
			{
				for (int y = 0; y < 8; y++)
				{
					FColor = 0x44E + (x * 8 + y);
					DWORD clr = UO->m_ColorManager->GetPolygoneColor(cell, FColor);
					UO->m_GL.DrawPolygone(clr, 490 + (x * 20), 140 + (y * 35.0f), 20.0f, 35.0f);
					if (g_LastSelectedObject == 40 + (x * 8 + y)) UO->m_GL.DrawPolygone(0x007F7F7F, 490 + ((x * 20) + 9), 140 + ((y * 34.0f) + 17.5f), 2.0f, 2.0f);
				}
			}
			glColor3f(1.0f, 1.0f, 1.0f);
			glEnable(GL_TEXTURE_2D);
		}
		else if (UO->m_CharacterCreate.GetSelectColor() == 0)
		{
			FColor = 0x0481;
			if (CanSelectedButton == 10) FColor = 0x0021;
			UO->m_Font->DrawA(9, "Hair Color", FColor, 490, 275);

			glDisable(GL_TEXTURE_2D);

			FColor = UO->m_CharacterCreate.GetHairColor();
			if (FColor < 0x044E) FColor = 0x044E;
			if (FColor > 0x04AD) FColor = 0x04AD;
			DWORD clr = UO->m_ColorManager->GetPolygoneColor(cell, FColor);
			UO->m_GL.DrawPolygone(clr, 490, 289, 120, 25);

			glColor3f(1.0f, 1.0f, 1.0f);
			glEnable(GL_TEXTURE_2D);
		}

		if (UO->m_CharacterCreate.GetSex())
		{
			UO->DrawGump(0x0760, UO->m_CharacterCreate.GetSkinTone(), 238, 98); //Character create female body gump
			UO->DrawGump(0x0714, UO->m_CharacterCreate.GetShirtColor(), 238, 98); //Character create skirt
			UO->DrawGump(0x0764, UO->m_CharacterCreate.GetPantsColor(), 238, 98); //Character create dress
			if (UO->m_CharacterCreate.GetHairStyle()) UO->DrawGump(UO->m_CharacterCreate.GetHair(UO->m_CharacterCreate.GetHairStyle()).GumpID, UO->m_CharacterCreate.GetHairColor(), 238, 98); //Character hair

			GumpID = 0x070D + (int)(CanSelectedButton == 4); //Character female button
			if (CanPressedButton == 4) GumpID = 0x070F; //Character female button pressed
			UO->DrawGump(GumpID, 0, 310, 408);
		}
		else
		{
			if (UO->m_CharacterCreate.GetSelectColor() == 5)
			{
				glDisable(GL_TEXTURE_2D);
				for (int x = 0; x < 6; x ++)
				{
					for (int y = 0; y < 8; y++)
					{
						FColor = 0x44E + (x * 8 + y);
						DWORD clr = UO->m_ColorManager->GetPolygoneColor(cell, FColor);
						UO->m_GL.DrawPolygone(clr, 490 + (x * 20), 140 + (y * 35.0f), 20.0f, 35.0f);
						if (g_LastSelectedObject == 40 + (x * 8 + y)) UO->m_GL.DrawPolygone(0x007F7F7F, 490 + ((x * 20) + 9), 140 + ((y * 34.0f) + 17.5f), 2.0f, 2.0f);
					}
				}
				glColor3f(1.0f, 1.0f, 1.0f);
				glEnable(GL_TEXTURE_2D);
			}
			else if (UO->m_CharacterCreate.GetSelectColor() == 0)
			{
				FColor = 0x0481;
				if (CanSelectedButton == 11) FColor = 0x0021;
				UO->m_Font->DrawA(9, "Facial Hair Color", FColor, 490, 320);

				glDisable(GL_TEXTURE_2D);

				FColor = UO->m_CharacterCreate.GetFacialHairColor();
				if (FColor < 0x044E) FColor = 0x044E;
				if (FColor > 0x04AD) FColor = 0x04AD;
				DWORD clr = UO->m_ColorManager->GetPolygoneColor(cell, FColor);
				UO->m_GL.DrawPolygone(clr, 490, 333, 120, 25);

				glColor3f(1.0f, 1.0f, 1.0f);
				glEnable(GL_TEXTURE_2D);
			}

			UO->DrawGump(0x0761, UO->m_CharacterCreate.GetSkinTone(), 238, 98); //Character create male body gump
			UO->DrawGump(0x0739, UO->m_CharacterCreate.GetShirtColor(), 238, 98); //Character create shirt
			UO->DrawGump(0x0738, UO->m_CharacterCreate.GetPantsColor(), 238, 98); //Character create pants
			UO->DrawGump(0x0762, 0, 238, 98); //Character create shoes
			if (UO->m_CharacterCreate.GetHairStyle()) UO->DrawGump(UO->m_CharacterCreate.GetHair(UO->m_CharacterCreate.GetHairStyle()).GumpID, UO->m_CharacterCreate.GetHairColor(), 238, 98); //Character hair
			if (UO->m_CharacterCreate.GetFacialHairStyle()) UO->DrawGump(UO->m_CharacterCreate.GetFacialHair(UO->m_CharacterCreate.GetFacialHairStyle()).GumpID, UO->m_CharacterCreate.GetFacialHairColor(), 238, 98); //Character facial hair

			GumpID = 0x0710 + (int)(CanSelectedButton == 4); //Character male button
			if (CanPressedButton == 4) GumpID = 0x0712; //Character male button pressed
			else UO->DrawGump(GumpID, 0, 310, 408);
		}

		UO->DrawCursor(0x2073); //Main Gump mouse cursor

		UO->m_GL.EndDraw();
	}
	else
	{
		g_LastSelectedObject = 0;
		g_LastObjectType = SOT_NO_OBJECT;

		if (UO->GumpPixelsInXY(0x1589, 555, 4))
		{
			g_LastSelectedObject = 1; //X gump
		}
		if (UO->GumpPixelsInXY(0x15A1, 586, 445))
		{
			g_LastSelectedObject = 2; //< gump
		}
		if (UO->GumpPixelsInXY(0x15A4, 610, 445))
		{
			g_LastSelectedObject = 3; //> gump
		}
		
		WORD GumpID = 0x0710;
		if (UO->m_CharacterCreate.GetSex()) GumpID = 0x070D;
		if (UO->GumpPixelsInXY(GumpID, 310, 408))
		{
			g_LastSelectedObject = 4; //male / female button
		}

		if (!UO->m_CharacterCreate.GetSex())
		{
			if (UO->m_CharacterCreate.GetSelectFace() != 2)
			{
				if (UO->ResizepicPixelsInXY(0xBB8, 97, 199, 121, 24))
				{
					g_LastSelectedObject = 5; //Facial Hair text field
				}
			}
			else
			{
				for (int i = 0; i < 8; i++)
				{
					RECT rc = {0, 0, 170, 25};
					POINT p = {g_MouseX - 101, g_MouseY - (205 + (i * 14))};
					if (PtInRect(&rc, p))
					{
						g_LastSelectedObject = (20 + i); //Facial Hair text field extended
					}
				}
			}
		}

		if (UO->m_CharacterCreate.GetSelectFace() != 1)
		{
			if (UO->ResizepicPixelsInXY(0xBB8, 97, 154, 121, 24))
			{
				g_LastSelectedObject = 6; //Hair text field
			}
		}
		else
		{
			for (int i = 0; i < 10 + (int)UO->m_CharacterCreate.GetSex(); i++)
			{
				RECT rc = {0, 0, 123, 25};
				POINT p = {g_MouseX - 101, g_MouseY - (159 + (i * 14))};
				if (PtInRect(&rc, p))
				{
					g_LastSelectedObject = (20 + i); //Hair text field extended
				}
			}
		}
		
		if (UO->m_CharacterCreate.GetSelectColor() == 1)
		{
			RECT rc = {0, 0, 120, 280};
			POINT p = {g_MouseX - 490, g_MouseY - 140};
			if (PtInRect(&rc, p))
			{
				int x = p.x / 15;
				int y = p.y / 35;

				int Index = (x * 8 + y);

				g_LastSelectedObject = 40 + Index;
				WORD ST = 0x03EA + Index;

				if (ST > 0x0422) ST = 0x0422;
				UO->m_CharacterCreate.SetSkinTone(ST);
			}
		}
		else if (UO->m_CharacterCreate.GetSelectColor() == 0)
		{
			RECT rc = {0, 0, 120, 40};
			POINT p = {g_MouseX - 491, g_MouseY - 139};
			if (PtInRect(&rc, p))
			{
				g_LastSelectedObject = 7;
			}
		}
		
		if (UO->m_CharacterCreate.GetSelectColor() == 2)
		{
		}
		else if (UO->m_CharacterCreate.GetSelectColor() == 0)
		{
			RECT rc = {0, 0, 120, 40};
			POINT p = {g_MouseX - 491, g_MouseY - 184};
			if (PtInRect(&rc, p))
			{
				g_LastSelectedObject = 8;
			}
		}
		
		if (UO->m_CharacterCreate.GetSelectColor() == 3)
		{
		}
		else if (UO->m_CharacterCreate.GetSelectColor() == 0)
		{
			RECT rc = {0, 0, 120, 40};
			POINT p = {g_MouseX - 491, g_MouseY - 229};
			if (PtInRect(&rc, p))
			{
				g_LastSelectedObject = 9;
			}
		}
		
		if (UO->m_CharacterCreate.GetSelectColor() == 4)
		{
			RECT rc = {0, 0, 120, 280};
			POINT p = {g_MouseX - 490, g_MouseY - 140};
			if (PtInRect(&rc, p))
			{
				int x = p.x / 20;
				int y = p.y / 35;
				int Index = (x * 8 + y);
				g_LastSelectedObject = 40 + Index;
				UO->m_CharacterCreate.SetHairColor(0x44E + Index);
			}
		}
		else if (UO->m_CharacterCreate.GetSelectColor() == 0)
		{
			RECT rc = {0, 0, 120, 40};
			POINT p = {g_MouseX - 491, g_MouseY - 274};
			if (PtInRect(&rc, p))
			{
				g_LastSelectedObject = 10;
			}
		}

		if (!UO->m_CharacterCreate.GetSex())
		{
			if (UO->m_CharacterCreate.GetSelectColor() == 5)
			{
				RECT rc = {0, 0, 120, 280};
				POINT p = {g_MouseX - 490, g_MouseY - 140};
				if (PtInRect(&rc, p))
				{
					int x = p.x / 20;
					int y = p.y / 35;
					int Index = (x * 8 + y);
					g_LastSelectedObject = 40 + Index;
					UO->m_CharacterCreate.SetFacialHairColor(0x44E + Index);
				}
			}
			else if (UO->m_CharacterCreate.GetSelectColor() == 0)
			{
				RECT rc = {0, 0, 120, 40};
				POINT p = {g_MouseX - 491, g_MouseY - 319};
				if (PtInRect(&rc, p))
				{
					g_LastSelectedObject = 11;
				}
			}
		}

		return g_LastSelectedObject;
	}
	return 0;
}
//---------------------------------------------------------------------------
void TCreateCharacterGump::ParseLeftMouseDown()
{
	Render(false);

	g_DroppedLeftMouseX = g_MouseX;
	g_DroppedLeftMouseY = g_MouseY;
	g_LeftMouseDown = true;
	g_LastObjectLeftMouseDown = g_LastSelectedObject;

	if (g_LastSelectedObject == 0)
	{
		if (UO->m_CharacterCreate.GetSelectFace() != 0x00)
		{
			UO->m_CharacterCreate.SetSelectFace(0x00);
		}
		return;
	}

	if (!UO->m_CharacterCreate.GetSex())
	{
		if (UO->m_CharacterCreate.GetSelectFace() != 2)
		{
			if (g_LastSelectedObject == 5)
			{
				UO->m_CharacterCreate.SetSelectFace(0x02);
				return;
			}
		}
		else
		{
			for (int i = 0; i < 8; i++)
			{
				if (g_LastSelectedObject == 20  + i)
				{
					UO->m_CharacterCreate.SetFacialHairStyle((BYTE)i);
					UO->m_CharacterCreate.SetSelectFace(0x00);
					return;
				}
			}
		}
	}

	if (UO->m_CharacterCreate.GetSelectFace() != 1)
	{
		if (g_LastSelectedObject == 6)
		{
			UO->m_CharacterCreate.SetSelectFace(0x01);
			return;
		}
	}
	else
	{
		for (int i = 0; i < 10 + (int)UO->m_CharacterCreate.GetSex(); i++)
		{
			if (g_LastSelectedObject == 20  + i)
			{
				UO->m_CharacterCreate.SetHairStyle((BYTE)i);
				UO->m_CharacterCreate.SetSelectFace(0x00);
				return;
			}
		}
	}
		
	if (g_LastSelectedObject == 7 || g_LastSelectedObject >= 40)
	{
		if (UO->m_CharacterCreate.GetSelectColor() == 1) //Skin Tone
		{
			UO->m_CharacterCreate.SetSelectColor(0);
			return;
		}
		else if (UO->m_CharacterCreate.GetSelectColor() == 0)
		{
			UO->m_CharacterCreate.SetSelectColor(1);
		}
	}
	
	if (g_LastSelectedObject == 8 || g_LastSelectedObject >= 110)
	{
		if (UO->m_CharacterCreate.GetSelectColor() == 2) //Shirt Color
		{
			UO->m_CharacterCreate.SetSelectColor(0);
			return;
		}
		else if (UO->m_CharacterCreate.GetSelectColor() == 0)
		{
			UO->m_CharacterCreate.SetSelectColor(2);
		}
	}
	
	if (g_LastSelectedObject == 9 || g_LastSelectedObject >= 110)
	{
		if (UO->m_CharacterCreate.GetSelectColor() == 3) //Skirt / Pants Color
		{
			UO->m_CharacterCreate.SetSelectColor(0);
			return;
		}
		else if (UO->m_CharacterCreate.GetSelectColor() == 0)
		{
			UO->m_CharacterCreate.SetSelectColor(3);
		}
	}
	
	if (g_LastSelectedObject == 10 || g_LastSelectedObject >= 40)
	{
		if (UO->m_CharacterCreate.GetSelectColor() == 4) //Hair Color
		{
			UO->m_CharacterCreate.SetSelectColor(0);
			return;
		}
		else if (UO->m_CharacterCreate.GetSelectColor() == 0)
		{
			UO->m_CharacterCreate.SetSelectColor(4);
		}
	}

	if (!UO->m_CharacterCreate.GetSex())
	{
		if (g_LastSelectedObject == 11 || g_LastSelectedObject >= 40)
		{
			if (UO->m_CharacterCreate.GetSelectColor() == 5) //Facial Hair Color
			{
				UO->m_CharacterCreate.SetSelectColor(0);
			}
			else if (UO->m_CharacterCreate.GetSelectColor() == 0)
			{
				UO->m_CharacterCreate.SetSelectColor(5);
			}
		}
	}
}
//---------------------------------------------------------------------------
void TCreateCharacterGump::ParseLeftMouseUp()
{
	Render(false);

	g_LeftMouseDown = false;
	g_DroppedLeftMouseX = 0;
	g_DroppedLeftMouseY = 0;

	if (g_LastSelectedObject == 0 || g_LastSelectedObject != g_LastObjectLeftMouseDown)
	{
		g_LastObjectLeftMouseDown = 0;
		return;
	}

	if (g_LastObjectLeftMouseDown == 1) //x button
	{
		PostQuitMessage(0);
		if (UO != NULL) delete UO;
		UO = NULL;
		return;
	}
	else if (g_LastObjectLeftMouseDown == 2) //< button
	{
		UO->InitGump(GS_CHARACTER);
	}
	else if (g_LastObjectLeftMouseDown == 3) //> button
	{
		if (UO->m_CharacterCreate.GetName() == string(""))
		{
			UO->InitGump(GS_GAME_CONNECT);
			UO->SetGameConnectionError(1);
		}
		else UO->InitGump(GS_CREATE_SELECT_TOWN);
	}
	else if (g_LastSelectedObject == 4)
	{
		UO->m_CharacterCreate.SetSex(!UO->m_CharacterCreate.GetSex());
	}

	g_LastObjectLeftMouseDown = 0;
}
//---------------------------------------------------------------------------
void TCreateCharacterGump::ParseRightMouseDown()
{
}
//---------------------------------------------------------------------------
void TCreateCharacterGump::ParseRightMouseUp()
{
}
//---------------------------------------------------------------------------
bool TCreateCharacterGump::ParseLeftMouseDoubleClick()
{
	return false;
}
//---------------------------------------------------------------------------
bool TCreateCharacterGump::ParseRightMouseDoubleClick()
{
	return false;
}
//---------------------------------------------------------------------------
void TCreateCharacterGump::ParseMouseWheel(MOUSE_WHEEL_STATE state)
{
}
//---------------------------------------------------------------------------
void TCreateCharacterGump::ParseCharPress(WPARAM wparam, LPARAM lparam)
{
	if (m_FontIndex[wparam] == 0xFF) return;
	char ch[2] = {0};
	ch[0] = wparam;
	if (strlen((char*)ch) < 1 || UO->m_CharacterCreate.GetName().length() > 20) return;
	UO->m_CharacterCreate.InsertName(ch);
}
//---------------------------------------------------------------------------
void TCreateCharacterGump::ParseKeyPress(WPARAM wparam, LPARAM lparam)
{
	switch (wparam)
	{
		case VK_HOME:
		{
			UO->m_CharacterCreate.SetNamePos(0);
			return;
		}
		case VK_END:
		{
			UO->m_CharacterCreate.SetNamePos(UO->m_CharacterCreate.GetName().length());
			return;
		}
		case VK_LEFT:
		{
			int np = UO->m_CharacterCreate.GetNamePos();
			if (np > 0) UO->m_CharacterCreate.SetNamePos(np - 1);
			return;
		}
		case VK_RIGHT:
		{
			int np = UO->m_CharacterCreate.GetNamePos();
			if (np < UO->m_CharacterCreate.GetName().length()) UO->m_CharacterCreate.SetNamePos(np + 1);
			return;
		}
		case VK_BACK:
		{
			int NamePos = UO->m_CharacterCreate.GetNamePos();
			string cName = UO->m_CharacterCreate.GetName();
			if (NamePos > 0 && NamePos <= cName.length())
			{
				if (NamePos == cName.length())
				{
					NamePos--;
					cName.resize(NamePos);
					UO->m_CharacterCreate.SetNamePos(NamePos);
					UO->m_CharacterCreate.SetName(cName);
				}
				else
				{
					char str[30] = {0};
					strncpy(str, cName.c_str(), cName.length());
					memmove(str + NamePos - 1, str + NamePos, cName.length() - NamePos);
					str[cName.length() - 1] = 0;
					cName = str;
					UO->m_CharacterCreate.SetName(cName);
					UO->m_CharacterCreate.SetNamePos(NamePos - 1);
				}
			}
			return;
		}
		case VK_DELETE:
		{
			int NamePos = UO->m_CharacterCreate.GetNamePos();
			string cName = UO->m_CharacterCreate.GetName();
			if (NamePos < cName.length())
			{
				if (NamePos == (cName.length() - 1))
				{
					cName.resize(NamePos);
					UO->m_CharacterCreate.SetName(cName);
				}
				else
				{
					char str[30] = {0};
					strncpy(str, cName.c_str(), cName.length());
					memmove(str + NamePos, str + NamePos + 1, cName.length() - NamePos - 1);
					str[cName.length() - 1] = 0;
					cName = str;
					UO->m_CharacterCreate.SetName(cName);
				}
			}
			return;
		}
		default: break;
	}
}
//---------------------------------------------------------------------------